#pragma once

#include<iostream>
#include<unistd.h>
#include<fcntl.h>
#include<vector>
#include<string>
#include<stdlib.h>

namespace ns_comm{
  void SetNonBlock(int sock){
    int f1 = fcntl(sock,F_GETFL);
    fcntl(sock,F_SETFL,f1|O_NONBLOCK);
  }  
  
  class StringUtil{
    public:
      static void Split(std::string &in,std::vector<std::string>* out, std::string sep )
      {
        while(true){
           size_t pos = in.find(sep);
           if(pos == std::string::npos){
             break;
           }
           std::string s = in.substr(0,pos);
           out->push_back(s);
           in.erase(0,pos+sep.size());
        }

      }
      static void Deserialize(std::string& in,int *x ,int* y){
         //1+4,100+4400
         size_t pos = in.find("+");
         std::string left = in.substr(0,pos);
         std::string right = in.substr(pos+1);

         *x = aoti(left.c_str());
         *y = aoti(right.c_str());
      }

  };

}
